package com.easyadmin.entity.po;

import com.easyadmin.entity.enums.DateTimePatternEnum;
import com.easyadmin.utils.DateUtil;
import com.fasterxml.jackson.annotation.JsonFormat;

import java.io.Serializable;


/**
 * 定时任务执行记录
 */
@SuppressWarnings("serial")
public class SysTaskRunLog implements Serializable {


    /**
     *
     */
    private Integer id;

    /**
     * 任务ID
     */
    private Integer taskId;

    /**
     * 开始时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private java.util.Date startTime;

    /**
     * 结束时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private java.util.Date endTime;

    /**
     * 执行结果 0:失败  1:成功
     */
    private Integer result;

    /**
     * 错误信息
     */
    private String errorInfo;


    private String runTime;

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return this.id;
    }

    public void setTaskId(Integer taskId) {
        this.taskId = taskId;
    }

    public Integer getTaskId() {
        return this.taskId;
    }

    public void setStartTime(java.util.Date startTime) {
        this.startTime = startTime;
    }

    public java.util.Date getStartTime() {
        return this.startTime;
    }

    public void setEndTime(java.util.Date endTime) {
        this.endTime = endTime;
    }

    public java.util.Date getEndTime() {
        return this.endTime;
    }

    public void setResult(Integer result) {
        this.result = result;
    }

    public Integer getResult() {
        return this.result;
    }

    public void setErrorInfo(String errorInfo) {
        this.errorInfo = errorInfo;
    }

    public String getErrorInfo() {
        return this.errorInfo;
    }

    public String getRunTime() {
        if (startTime != null && endTime != null) {
            runTime = endTime.getTime() - startTime.getTime() + "毫秒";
        }
        return runTime;
    }

    public void setRunTime(String runTime) {
        this.runTime = runTime;
    }

    @Override
    public String toString() {
        return "id:" + (id == null ? "空" : id) + "，任务ID:" + (taskId == null ? "空" : taskId) + "，开始时间:" + (startTime == null ? "空" : DateUtil.format(startTime,
                DateTimePatternEnum.YYYY_MM_DD_HH_MM_SS.getPattern())) + "，结束时间:" + (endTime == null ? "空" : DateUtil.format(endTime,
                DateTimePatternEnum.YYYY_MM_DD_HH_MM_SS.getPattern())) + "，执行结果 0:失败  1:成功:" + (result == null ? "空" : result) + "，错误信息:" + (errorInfo == null ? "空" :
                errorInfo);
    }
}
